<template>
  <div class="maxWidth">
    <h1 class="flexCon marT37 fontS30 fonBold">
      安徽省广播电视联合会专业技术委员会技术进步奖（2022年度）
    </h1>
    <div class="infoItemBox wBgColor marT37">
      <div style="margin-bottom:20px">
        <a-alert message="请完成如下表单信息填写，并提交对应的盖章附件" type="warning" />
      </div>
      <div
        class="itemBox flexWrap"
        :class="[type != 'info' ? 'flexLeft' : 'flexBet']"
      >
        <div
          class="fontS20 infoItem cup"
          v-for="(i, k) in projectInfoItemList"
          :class="{
            marB35: k < 5 || (k < 10 && k > 0),
            currentItem: current == i.id,
            marR40: (k % 4 != 0 || k == 0) && type != 'info',
          }"
          :key="i.id"
          @click="changeInfoItem(i.id)"
        >
          {{ i.name }}
        </div>
      </div>
    </div>
    <!-- 申报详情表单 -->
    <div class="infoForm wBgColor marT15">
      <!-- 操作 -->
      <div
        :class="[
          (prizeTypeId != 1 && 'flexRight') ||
            (current == 1 ? 'flexBet' : 'flexRight'),
        ]"
      >
        <div v-if="current == 1 && prizeTypeId == 1">
        <!-- <a-tag color="orange">当前页需要推荐单位盖章</a-tag> -->
          <!-- 推荐单位（盖章） ：<input
            type="text"
            placeholder="这里推荐单位盖章"
            disabled
          /> -->
          <!-- 编号：<input type="text" placeholder="科技处填写" /> -->
        </div>
        <!-- buttons -->
        <div>
          <a-button type="primary" class="marR10" size="small" @click="save">
            保存
          </a-button>
          <!-- <a-button type="primary" size="small" class="marR10" @click="sub">
            提交
          </a-button> -->
          <a-dropdown style=" background-color: #1890ff;">
              <a-menu slot="overlay" @click="handleMenuClick">
               <a-menu-item key="1"> 基本信息情况</a-menu-item>
               <a-menu-item key="2"> 推荐单位意见</a-menu-item>
               <a-menu-item key="3"> 主要完成单位</a-menu-item>
               <a-menu-item key="4"> 主要完成人</a-menu-item>
              </a-menu>
              <a-button size="small" style="margin-left: 8px; color:#fff">下载pdf <a-icon type="down" /> </a-button>
          </a-dropdown>
        </div>
      </div>
      <!-- 进步奖 -->
      <formGather
        :index="current"
        :id="prizeTypeId"
        :basrId="baseId"
        v-on:ossUpLoadSuccess="ossUpLoadSuccess"
      />
    </div>
    <!-- 版权 -->
    <div class="fontS14 marT30 padB30 flexCon">
      Copyright @2021 All Rights Reserved
    </div>
  </div>
</template>

<script>
import formGather from "@/components/form/formGather";
// import deerAwardIndex from "@/components/deerAward/index";
import { mapState } from "vuex";
import { addOrUpdate, addOrUpdateAndCommit, projectInfo } from "@/api";
import { info, add } from "@/assets/js/declare.js";
export default {
  components: {
    // eslint-disable-next-line vue/no-unused-components
    formGather,
    // deerAwardIndex,
  },
  data() {
    return {
      current: 1,
      prizeTypeId: "",
      type: "", // 进入页面获取类型 // add 新建  info 查看详情
      projectInfoItemList: [],
      baseId: "",
      id: "https://www.ahwanyun.cn/FR/ReportServer?reportlet=gdy/gdy_kxjbj_sqb.cpt&base_id=",
    };
  },
  computed: {
    ...mapState({
      declare: (state) => state.declare,
    }),
  },
  destroyed() {
    let str = sessionStorage.getItem("declare");
    this.type && this.$store.commit("SET_DECLARE_ALL", JSON.parse(str));
  },
  created() {
    //  this.$router.go(0)
    // this.$store.commit("RESET_STATE");
    console.log(111111111111)
    this.$route.params.baseId && (this.id += this.$route.params.baseId);
    this.getData();
    this.$store.commit("NEW_SET_DECLARE_ALL", this.declare);
    this.baseId = this.$route.params.baseId;
  },
  mounted(){
    // if (location.href.indexOf("#/index/declareDetails") == -1) {
    //   location.href = location.href + "#/index/declareDetails";
    //   location.reload();
    // }
  },

  methods: {
    getData() {
      this.prizeTypeId = this.$route.query.id;
      this.type = this.$route.params.type; // 技术进步奖 预览还是添加
      this.projectInfoItemList = this.type == "info" ? info : add;
      this.$route.params.type && this.getProjectInfo(this.$route.params.baseId); //预览
      this.$route.query.id &&
        this.$store.commit("SET_DECLARE_ITEM", {
          ajaxStr: "prizeTypeId",
          value: this.$route.query.id,
        }); // 申报

      this.$store.commit("SET_IPT_DIS", this.type == "info");
    },
    changeInfoItem(k) {
      this.current = k;
    },
    async getProjectInfo(id) {
      const res = await projectInfo(id);
      if (res.code != 200) return;
      this.$store.commit("FILTER_DECLARE_DATA", res.data);
    },
    // 保存
    save() {
      console.log(JSON.parse(sessionStorage.getItem("userInfo")).roles[0].roleName)
      if(JSON.parse(sessionStorage.getItem("userInfo")).roles[0].roleName == '推荐单位角色'){
          this.$notification.error({
          message: "提示",
          description: "推荐单位角色不能申报",
        });
        return false;
      } 
      this.$store.commit("NEW_SET_DECLARE_ALL", this.declare);
      if (this.declare.baseName == "") {
        this.$notification.error({
          message: "提示",
          description: "请输入项目名称",
        });
        return false;
      }
      // console.log(this.declare)
      this.declare.deptName = this.declare.deptName
        .replace(/，/gi, ",")
        .replace(/、/gi, "，");
      if (this.declare.secretLevel == 2)
        return this.$message.error("涉密项目只能线下申报");
      addOrUpdate(this.$store.state.newDeclare).then((res) => {
        if (res.code != 200) return this.$message.error(res.msg);
        this.$notification.success({
          message: "提示",
          description: "保存成功",
        });
        this.id += res.msg;
        this.$store.commit("SET_BASE_ID", res.msg);
        this.$store.commit("RESET_STATE");
      });
    },
    // 提交
    sub() {
      this.$store.commit("NEW_SET_DECLARE_ALL", this.declare);
      this.declare.deptName = this.declare.deptName
        .replace(/，/gi, ",")
        .replace(/、/gi, ",");
      if (this.declare.secretLevel == 2)
        return this.$message.error("涉密项目只能线下申报");
      addOrUpdateAndCommit(this.$store.state.newDeclare).then((res) => {
        if (res.code != 200) return this.$message.error(res.msg);
        let str = sessionStorage.getItem("declare");
        this.$store.commit("SET_DECLARE_ALL", JSON.parse(str));
        this.$notification.success({
          message: "提示",
          description: "提交成功,正在跳转...",
        });
        setTimeout(() => {
          this.$router.push("/myDeclare");
        }, 1000);
      });
    },
    // 下拉打印
    handleMenuClick(e){
      console.log(this.baseId)
      if(this.baseId!=null&&this.baseId!=''){
        if(1==e.key){
          window.open('_blank').location='https://www.ahwanyun.cn/FR/ReportServer?reportlet=gdy/gdy_kxjbj_sqb_no1.cpt&base_id='+this.baseId
        }else if(2==e.key){
          window.open('_blank').location='https://www.ahwanyun.cn/FR/ReportServer?reportlet=gdy/gdy_kxjbj_sqb_no2.cpt&base_id='+this.baseId
        }else if(3==e.key){
          window.open('_blank').location='https://www.ahwanyun.cn/FR/ReportServer?reportlet=gdy/gdy_kxjbj_sqb_no3.cpt&base_id='+this.baseId
        }else if(4==e.key){
          window.open('_blank').location='https://www.ahwanyun.cn/FR/ReportServer?reportlet=gdy/gdy_kxjbj_sqb_no4.cpt&base_id='+this.baseId
        }
      }else{
        this.$notification.warning({
          message: "提示",
          description: "当前作品尚未提交，不能下载",
        });
      }

    },
    // 上传附件
    ossUpLoadSuccess(id) {
      !Array.isArray(this.declare.fileIds) && (this.declare.fileIds = []);
      this.declare.fileIds.push(id);
    },
  },
};
</script>

<style lang="scss" scoped>
.infoItemBox {
  padding: 45px 20px;
  border-radius: 12px;
  border: 1px solid #cfdbe8;
  .infoItem {
    min-width: 186px;
    text-align: center;
    border-radius: 2px;
    background-color: #e9edf2;
    font-weight: 500;
    padding: 6px 15px;
    box-sizing: border-box;
    border-radius: 5px;
  }
  .currentItem {
    color: #fff;
    background-color: #1a60ff;
  }
}
.infoForm {
  padding: 25px 20px;
  border: 1px solid #cfdbe8;
  border-radius: 12px;
}
</style>
